package com.bajiao.common.util;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @Description: ID随机数生成工具
 * @Author: GuoYu
 * @Date: 2024-10-10/7/2
 * @Version: V1.0
 */
public class IdUtil {
    private static char[] chars = {'2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

    /**
     * 获取配资平台随机Id
     * @return
     */
    public static synchronized String getLoanPlatId() {
        long current = System.currentTimeMillis();
        Random rand = new Random();
        // 产生一个随机数
        long randNum = rand.nextInt(1000000) + 1000000L;
        StringBuffer sb = new StringBuffer();
        sb.append(current);
        sb.append(randNum);
        return sb.toString();
    }

    /**
     * 生产随机数
     * @param length 位数
     */
    public static String getRandomIntString(int length,String seed) {
        int subIndex;
        StringBuilder retString = new StringBuilder();
        for (int i = 0; i < length; i++) {
            subIndex = (int) (ThreadLocalRandom.current().nextDouble() * 100 % seed.length());
            retString.append(seed, subIndex, subIndex + 1);
        }
        return retString.toString();
    }
    public static String randomString(long seed, int length) {
        Random random = new Random(seed);
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < length; j++) {
            int number = random.nextInt(32);
            sb.append(chars[number]);
        }
        return sb.toString();
    }
    /**
     * 生成32位uuid
     * @return uuid
     */
    public static String getUUID() {
        UUID uuid = UUID.randomUUID();
        String result = uuid.toString();
        result = result.replace("-", "");
        return result;
    }

    /**
     * 生成一个8位的随机数
     * @return
     */
    public static String get8Random() {
        Random rand = new Random();
        long randNum = rand.nextInt(10000000) + 10000000L;
        return String.valueOf(randNum);
    }
}
